<?php

namespace kuaidi;

class Kuaidi100 {

    public function track($filter) {
        //参数设置
        $info = cmf_get_site_info();  //基本参数
        $post_data = array();
        $post_data["customer"] = $info['kuaidi100_customer'];
        $key= $info['kuaidi100_key'];
        $post_data["param"] = '{"com":"'.$filter['com'].'","num":"'.$filter['num'].'"}';

        $url='http://poll.kuaidi100.com/poll/query.do';
        $post_data["sign"] = md5($post_data["param"].$key.$post_data["customer"]);
        $post_data["sign"] = strtoupper($post_data["sign"]);
        $o="";
        //var_dump($post_data);exit;
        foreach ($post_data as $k=>$v) {
            $o.= "$k=".urlencode($v)."&";       //默认UTF-8编码格式
        }
        $post_data=substr($o,0,-1);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $data = curl_exec($ch);
        curl_close($ch);
        $data = str_replace("\"",'"',$data );
        $data = json_decode($data,true);

        return $data;
    }
}
